package com.zzy.blog.action;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.zzy.blog.dao.pojo.User;

public class HttpAction extends ActionSupport{
	
	private User user;
	
	//接受字符串
//	public String server() {
//		logger.info(user);
//		HttpServletRequest request = ServletActionContext.getRequest();
//		logger.info("parameter1:" + request.getParameter("parameter1"));
//		logger.info("parameter2:" + request.getParameter("parameter2"));
//		
//		return SUCCESS;
//	}
	
	//接受byte[]
	public String server() throws IOException, ClassNotFoundException {
		HttpServletRequest request = ServletActionContext.getRequest();
		ObjectInputStream in = new ObjectInputStream(request.getInputStream());
		Map<Object, Object> data = (Map<Object, Object>) in.readObject();
		
		for(Map.Entry<Object, Object> entry : data.entrySet()) {
			System.out.println(entry.getKey() + "--------------->" + entry.getValue());
		}
		 
		return SUCCESS;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

}
